package com.cdks.wuxiu.api.service.mysql;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdks.wuxiu.api.component.constant.Constant;
import com.cdks.wuxiu.api.mapper.WithdrawAccountInfoMapper;
import com.cdks.wuxiu.entity.mysql.WithdrawAccountInfo;

import java.util.List;

import org.springframework.stereotype.Service;

/**
 * 提现账号表 服务实现类
 */
@Service
public class WithdrawAccountInfoServiceImpl extends ServiceImpl<WithdrawAccountInfoMapper, WithdrawAccountInfo> implements WithdrawAccountInfoService {
    @Override
    public List<WithdrawAccountInfo> getByUserIdWithType(long userId, List<Integer> type) {
        QueryWrapper<WithdrawAccountInfo> wrapper  = new QueryWrapper<>();
        wrapper.lambda().eq(WithdrawAccountInfo::getUserId, userId)
                        .eq(WithdrawAccountInfo::getStatus, Constant.ENABLE_YES)
                        .in(WithdrawAccountInfo::getType, type)
                        .select(WithdrawAccountInfo::getId,
                                WithdrawAccountInfo::getType,
                                WithdrawAccountInfo::getInfo);
        
        return baseMapper.selectList(wrapper);
    }

    @Override
    public WithdrawAccountInfo getByUserId(long userId, long acctId) {
        QueryWrapper<WithdrawAccountInfo> wrapper  = new QueryWrapper<>();
        wrapper.lambda().eq(WithdrawAccountInfo::getUserId, userId)
                        .eq(WithdrawAccountInfo::getId, acctId)
                        .eq(WithdrawAccountInfo::getStatus, Constant.ENABLE_YES);
        
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public int delAccount(long userId, long acctId) {
        int ret  = baseMapper.delAccount(userId, acctId);
        if (ret == 1)
        {
            return 0;
        }

        return -1;
    }
}
